package com.xinda.admin.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xinda.admin.pojo.ProductStyle;
import com.xinda.admin.pojo.ProductType;
import com.xinda.admin.service.ITypeService;

@Controller
public class TypeController {
	
	@Autowired
	@Qualifier("typeService")
	private ITypeService typeService;

	@RequestMapping(value="typeList")
	public String showTypeListPage(int styleId, Model model){
		
		List<ProductType> typeList = typeService.queryTypeList(styleId);
		List<ProductStyle> styleList = typeService.queryStyleList();
		
		model.addAttribute("styleId", styleId);
		model.addAttribute("count", typeList.size());
		model.addAttribute("typeList", typeList);
		model.addAttribute("styleList", styleList);
		model.addAttribute("stylecount", styleList.size());
		
		return "admin/type/typeList";
	}
	
	@RequestMapping(value="showEditTypePage")
	public String showEditTypePage(int id, Model model){
		
		ProductType type = typeService.queryTypeById(id);
		List<ProductStyle> styleList = typeService.queryStyleList();
		
		model.addAttribute("type", type);
		model.addAttribute("styleList", styleList);
		
		return "admin/type/editType";
	}
	
	@RequestMapping(value="showAddTypePage")
	public String showAddTypePage(Model model){
		List<ProductStyle> styleList = typeService.queryStyleList();
		model.addAttribute("styleList", styleList);
		return "admin/type/addType";
	}
	
	@RequestMapping(value="deleteType")
	@ResponseBody
	public void deleteType(int id){
		typeService.deleteTypeById(id);
	}
	
	@RequestMapping(value="typeUpdateOfStatus")
	@ResponseBody
	public void updateStatus(int id, int status){
		typeService.updateStatusById(id, status);
	}
	
	@RequestMapping(value="updateType")
	@ResponseBody
	public void updateType(ProductType type){
		typeService.updateTypeById(type);
	}
	
	@RequestMapping(value="addType")
	@ResponseBody
	public void addType(ProductType type){
		typeService.addTypeById(type);
	}
}
